#include <bits/stdc++.h>
using namespace std;
// char buf[1<<23],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
// #define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
    while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
    return x*f;
}
#define pii pair<int,int>
const int N=1e5+4,K=15;
int n,m,fa[N],a[N];
vector<int> g[N];
vector<pii> qu[N];
int dfn[N],nfd[N],cnt,sz[N],top[N],son[N],dep[N];
void dfs1(int x){
    sz[x]=1,dep[x]=dep[fa[x]]+1;
    for(auto y:g[x]){
        dfs1(y);
        sz[x]+=sz[y];
        if(sz[y]>sz[son[x]]) son[x]=y;
    }
}
void dfs2(int x,int tp){
    nfd[dfn[x]=++cnt]=x,top[x]=tp;
    if(son[x]) dfs2(son[x],tp);
    for(auto y:g[x]){
        if(y==son[x]) continue;
        dfs2(y,y);
    }
}
int lca(int x,int y){
	while(top[x]!=top[y]){
		if(dep[top[x]]<dep[top[y]]) swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}
namespace sgt{
    #define ls(x) (x<<1)
    #define rs(x) (x<<1|1)
    int t[N<<2];
    void build(int x,int l,int r){
        if(l==r) return t[x]=a[l],void();
        int mid=(l+r)>>1;
        build(ls(x),l,mid);
        build(rs(x),mid+1,r);
        t[x]=lca(t[ls(x)],t[rs(x)]);
    }
    int asklca(int x,int st,int ed,int l,int r){
        if(l<=st&&ed<=r) return t[x];
        int mid=(st+ed)>>1;
        if(r<=mid) return asklca(ls(x),st,mid,l,r);
        if(l>mid) return asklca(rs(x),mid+1,ed,l,r);
        return lca(asklca(ls(x),st,mid,l,r), asklca(rs(x),mid+1,ed,l,r));
    }
}
namespace bit{
    #define lowbit(x) (x&-x)
    int v[N];
    void upd(int x,int k){
        // cerr<<x<<" "<<k<<"\n";
        while(x<=n) v[x]+=k,x+=lowbit(x);
    }
    int qry(int x){
        int ans=0;
        while(x) ans+=v[x],x-=lowbit(x);
        return ans;
    }
}
namespace kdls{
    struct node{
        int l,r,v;
    };
    vector<node> t[N];
    void st(){
        for(int i=1;i<=n;i++)
            if(!son[i]){
                t[top[i]].push_back({1,dep[i]-dep[top[i]]+1,n+1});
            }
    }
    void modify(int x,int v){
        while(x){
            int r=dep[x]-dep[top[x]]+1;
            x=top[x];
            while(t[x].size()){
                node y=t[x].back();
                bit::upd(y.v,-(y.r-y.l+1));
                t[x].pop_back();
                if(y.l<=r&&y.r>r){
                    bit::upd(y.v,(y.r-(r+1)+1));
                    t[x].push_back({r+1,y.r,y.v});
                    break;
                }
                if(y.r==r) break;
            }
            t[x].push_back({1,r,v});
            bit::upd(v,r);
            x=fa[x];
        }
    }
}
int ans[N];
int main(){
    freopen("ex_escape2.in","r",stdin);
    freopen("escape.out","w",stdout);
    n=read(),m=read();
    for(int i=2;i<=n;i++) g[fa[i]=read()].push_back(i);
    for(int i=1;i<=n;i++) a[i]=read();
    dfs1(1),dfs2(1,1);
    kdls::st();
    sgt::build(1,1,n);
    for(int i=1;i<=m;i++){
        int l=read(),r=read();
        qu[l].push_back({r,i});
        // cerr<<sgt::asklca(1,1,n,l,r)<<"!!\n";
        ans[i]-=dep[sgt::asklca(1,1,n,l,r)]-1;
    }
    for(int i=n;i;i--){
        // cerr<<i<<"\n";
        kdls::modify(a[i],i);
        for(auto [x,id]:qu[i]) ans[id]+=bit::qry(x);
    }
    for(int i=1;i<=m;i++) cout<<ans[i]<<"\n";
    return 0;
}